package 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.Dictionary;
	import org.flixel.*;
	import data.*;
	/**
	 * ...
	 * @author Jason Won
	 */
	public class GCResources 
	{
		private static var dict:Dictionary;
		
		[Embed(source = '/assets/warehousebutton.png')]
		public static const warehouseButton:Class;	
		[Embed(source = '/assets/tradepostbutton.png')]
		public static const tradepostButton:Class;	
		[Embed(source = '/assets/assignworkerbutton.png')]
		public static const workerButton:Class;	
		[Embed(source = '/assets/marketbutton.png')]
		public static const marketButton:Class;	
		[Embed(source = '/assets/worldmap.png')]
		public static const worldMap:Class;	
		[Embed(source = '/assets/city.png')]
		public static const cityImage:Class;
		
		[Embed(source = '/assets/misc/face.png')]
		public static const face:Class;
		[Embed(source = '/assets/misc/goal.png')]
		public static const goal:Class;
		
		/** UI Components**/
		[Embed(source = "/assets/ui/down_arrow.png")] 
		public static const down_arrow:Class;
		[Embed(source = "/assets/ui/down_minus_arrow.png")] 
		public static const down_minus_arrow:Class;
		[Embed(source = "/assets/ui/left_arrow.png")] 
		public static const left_arrow:Class;
		[Embed(source = "/assets/ui/left_minus_arrow.png")] 
		public static const left_minus_arrow:Class;
		[Embed(source = "/assets/ui/right_arrow.png")] 
		public static const right_arrow:Class;
		[Embed(source = "/assets/ui/right_plus_arrow.png")] 
		public static const right_plus_arrow:Class;
		[Embed(source = "/assets/ui/up_arrow.png")] 
		public static const up_arrow:Class;
		[Embed(source = "/assets/ui/up_plus_arrow.png")] 
		public static const up_plus_arrow:Class;
		[Embed(source = "/assets/ui/slider_horizontal.png")] 
		public static const slider_horizonal:Class;
		[Embed(source = "/assets/ui/slider_large_vertical.png")] 
		public static const slider_large_vertical:Class;
		[Embed(source = "/assets/ui/slider_mini_vertical.png")] 
		public static const slider_mini_vertical:Class;
		[Embed(source = "/assets/ui/track_horizontal.png")] 
		public static const track_horizontal:Class;
		[Embed(source = "/assets/ui/track_vertical.png")] 
		public static const track_vertical:Class;
		[Embed(source = "/assets/ui/plate.png")] 
		public static const plate:Class;
		[Embed(source = "/assets/ui/toggles.png")] 
		public static const toggles:Class;
		[Embed(source = "/assets/ui/experience_bar.png")] 
		public static const experience_bar:Class;

		/** Resources **/
		
		// Ships
		[Embed(source = "/assets/ships/sailboat.png")] 
		public static const sailboat:Class;
		[Embed(source = "/assets/ships/galley.png")] 
		public static const galley:Class;
		[Embed(source = "/assets/ships/barge.png")] 
		public static const barge:Class;
		[Embed(source = "/assets/ships/steamboat.png")] 
		public static const steamboat:Class;
		
		// Upgrade
		[Embed(source = "/assets/upgrades/plus.png")]
		public static const plus:Class;
		[Embed(source = "/assets/upgrades/sail_1.png")] 
		public static const sail_1:Class;
		[Embed(source = "/assets/upgrades/sail_2.png")] 
		public static const sail_2:Class;
		[Embed(source = "/assets/upgrades/sail_3.png")] 
		public static const sail_3:Class;		
		[Embed(source = "/assets/upgrades/crows_nest.png")] 
		public static const crows_nest_upgrade:Class;
		[Embed(source = "/assets/upgrades/motor.png")] 
		public static const motor_upgrade:Class;
		[Embed(source = "/assets/upgrades/hull.png")] 
		public static const hull_upgrade:Class;
		[Embed(source = "/assets/upgrades/compass.png")] 
		public static const compass_upgrade:Class;
		[Embed(source = "/assets/upgrades/mast_aluminum.png")] 
		public static const mast_upgrade:Class;
		[Embed(source = "/assets/upgrades/mast_carbon.png")] 
		public static const mast_carbon_upgrade:Class;
		[Embed(source = "/assets/upgrades/crew_quarters.png")] 
		public static const crew_quarters_upgrade:Class;
		[Embed(source = "/assets/upgrades/anchor.png")] 
		public static const anchor_upgrade:Class;
		[Embed(source = "/assets/upgrades/cannon.png")] 
		public static const cannon_upgrade:Class;
		[Embed(source = "/assets/upgrades/emblem.png")] 
		public static const emblem_upgrade:Class;
		[Embed(source = "/assets/upgrades/statue.png")] 
		public static const statue_upgrade:Class;
		[Embed(source = "/assets/upgrades/ship_wheel.png")] 
		public static const wheel_upgrade:Class;
		[Embed(source = "/assets/upgrades/rudder.png")] 
		public static const rudder_upgrade:Class;
		[Embed(source = "/assets/upgrades/flag_1.png")] 
		public static const flag_1_upgrade:Class;
		[Embed(source = "/assets/upgrades/flag_2.png")] 
		public static const flag_2_upgrade:Class;
		[Embed(source = "/assets/upgrades/flag_3.png")] 
		public static const flag_3_upgrade:Class;
		[Embed(source = "/assets/upgrades/flag_4.png")] 
		public static const flag_4_upgrade:Class;
		
		// Harvestable Resources
		[Embed(source = "/assets/resources/food.png")] 
		public static const food:Class;
		[Embed(source = "/assets/resources/lumber.png")] 
		public static const lumber:Class;
		[Embed(source = "/assets/resources/iron.png")] 
		public static const iron:Class;
		[Embed(source = "/assets/resources/silver.png")] 
		public static const silver:Class;
		[Embed(source = "/assets/resources/copper.png")] 
		public static const copper:Class;
		[Embed(source = "/assets/resources/wool.png")] 
		public static const wool:Class;
		[Embed(source = "/assets/resources/cotton.png")] 
		public static const cotton:Class;
		[Embed(source = "/assets/resources/silk.png")] 
		public static const silk:Class;
		[Embed(source = "/assets/resources/salt.png")] 
		public static const salt:Class;
		[Embed(source = "/assets/resources/spices.png")] 
		public static const spices:Class;
		[Embed(source = "/assets/resources/oil.png")] 
		public static const oil:Class;
		[Embed(source = "/assets/resources/coal.png")] 
		public static const coal:Class;
		[Embed(source = "/assets/resources/crows_nest.png")] 
		public static const crows_nest:Class;
		[Embed(source = "/assets/resources/motor.png")] 
		public static const motor:Class;
		[Embed(source = "/assets/resources/compass.png")] 
		public static const compass:Class;
		[Embed(source = "/assets/resources/mast_carbon.png")] 
		public static const mast_carbon:Class;
		[Embed(source = "/assets/resources/mast_aluminum.png")] 
		public static const mast_aluminum:Class;
		[Embed(source = "/assets/resources/anchor.png")] 
		public static const anchor:Class;
		[Embed(source = "/assets/resources/cannon.png")] 
		public static const cannon:Class;
		[Embed(source = "/assets/resources/ship_wheel.png")] 
		public static const wheel:Class;
		[Embed(source = "/assets/resources/rudder.png")] 
		public static const rudder:Class;
		[Embed(source = "/assets/resources/gold.png")] 
		public static const gold:Class;
		
		/** Recipe **/
		[Embed(source = "/assets/resources/recipe.png")]
		public static const recipe:Class;
		
		/** Buildings **/
		[Embed(source = "/assets/buildings/mine.png")] 
		public static const mine:Class;
		[Embed(source = "/assets/buildings/lumber_yard.png")] 
		public static const lumber_yard:Class;
		[Embed(source = "/assets/buildings/farm.png")] 
		public static const farm:Class;
		[Embed(source = "/assets/buildings/oil_well.png")] 
		public static const oil_field:Class;
		[Embed(source = "/assets/buildings/warehouse.png")] 
		public static const warehouse:Class;
		[Embed(source = "/assets/buildings/factory.png")]
		public static const factory:Class;
		[Embed(source = "/assets/buildings/merchant_stall.png")]
		public static const stall:Class;
		
		// Paths
		[Embed(source = "/assets/routes/Allegio Routes.png")] 
		public static const allegioRoutes:Class;
		[Embed(source = "/assets/routes/Chuan Routes.png")] 
		public static const chuanRoutes:Class;
		[Embed(source = "/assets/routes/Chumbucket Routes.png")] 
		public static const chumbucketRoutes:Class;
		[Embed(source = "/assets/routes/Dunderfunk Routes.png")] 
		public static const dunderfunkRoutes:Class;
		[Embed(source = "/assets/routes/Hai Jing Routes.png")] 
		public static const haiJingRoutes:Class;
		[Embed(source = "/assets/routes/Hornswaggle Routes.png")] 
		public static const hornswaggleRoutes:Class;
		[Embed(source = "/assets/routes/Marino Routes.png")] 
		public static const marinoRoutes:Class;
		[Embed(source = "/assets/routes/Onda Routes.png")] 
		public static const ondaRoutes:Class;
		[Embed(source = "/assets/routes/Picaroon Routes.png")] 
		public static const picaroonRoutes:Class;
		[Embed(source = "/assets/routes/Shanban Routes.png")] 
		public static const shanbanRoutes:Class;
		[Embed(source = "/assets/routes/Tafferel Routes.png")] 
		public static const tafferelRoutes:Class;
		[Embed(source = "/assets/routes/Xebek Routes.png")] 
		public static const xebekRoutes:Class;
		
		// Background stuff
		[Embed(source = "/assets/wood_background.png")] 
		public static const wood_background:Class;
		private static var woodBMD:BitmapData = FlxG.addBitmap(wood_background);
		
		[Embed(source = "/assets/paper_background.png")] 
		public static const paper_background:Class;
		private static var paperBMD:BitmapData = FlxG.addBitmap(paper_background);
		
		[Embed(source = "/assets/canvas_background.png")] 
		public static const canvas_background:Class;
		private static var canvasBMD:BitmapData = FlxG.addBitmap(canvas_background);
		
		[Embed(source = "/assets/bottom_border.png")] 
		public static const border:Class;
		
		
		
		public static function getResource(resourceName:String):Bitmap
		{			
			var c:Class = dict[resourceName];		
			var bmd:BitmapData = FlxG.addBitmap(c);
			var myBitmap:Bitmap = new Bitmap(bmd);
			return myBitmap;
		}
		
		public static function getPaperBackground(width:int, height:int):Bitmap
		{		
			var x:int = width;
			var y:int = height;
			
			if(width <= paperBMD.width)
				x = Math.floor(Math.random() * (paperBMD.width - width));
			if (height <= paperBMD.height)
				y = Math.floor(Math.random() * (paperBMD.height - height));
				
			var rect:Rectangle = new Rectangle(x, y, width, height);
			var bmd:BitmapData = new BitmapData(width, height);
			var point:Point = new Point();
			bmd.copyPixels(paperBMD, rect, point);
			
			return new Bitmap(bmd);
		}
		
		public static function getWoodBackground(width:int, height:int):Bitmap
		{
			var x:int = width;
			var y:int = height;
			
			if(width <= woodBMD.width)
				x = Math.floor(Math.random() * (woodBMD.width - width));
			if (height <= woodBMD.height)
				y = Math.floor(Math.random() * (woodBMD.height - height));
				
			var rect:Rectangle = new Rectangle(x, y, width, height);
			var bmd:BitmapData = new BitmapData(width, height);
			var point:Point = new Point();
			bmd.copyPixels(woodBMD, rect, point);
			
			return new Bitmap(bmd);
		}
		
		public static function getCanvasBackgrounds(width:int, height:int):Bitmap
		{
			var x:int = width;
			var y:int = height;
			
			if(width <= canvasBMD.width)
				x = Math.floor(Math.random() * (canvasBMD.width - width));
			if (height <= canvasBMD.height)
				y = Math.floor(Math.random() * (canvasBMD.height - height));
				
			var rect:Rectangle = new Rectangle(x, y, width, height);
			var bmd:BitmapData = new BitmapData(width, height);
			var point:Point = new Point();
			bmd.copyPixels(canvasBMD, rect, point);
			
			return new Bitmap(bmd);
		}
		
		public static function getMaskedCanvasBackground(width:int, height:int, ellipseWidth:int = 20):Sprite
		{
			var mask:Shape = new Shape();
			var background:Sprite = new Sprite();
			
			mask.graphics.clear();
			mask.graphics.beginFill(0xFFFFFF);
			mask.graphics.drawRoundRect(0, 0, width, height, ellipseWidth);
			mask.graphics.endFill();			
			background.mask = mask;
			background.addChild(mask);
			
			background.addChild(getCanvasBackgrounds(width, height));
			
			return background;
		}
		
		
		public static function init():void
		{
			dict = new Dictionary();
			
			// Ships
			dict["Sailboat"] = sailboat;
			dict["Galley"] = galley;
			dict["Barge"] = barge;
			dict["Steamboat"] = steamboat;
			
			dict["tradepostButton"] = tradepostButton;
			dict["warehouseButton"] = warehouseButton;
			dict["workerassignButton"] = workerButton;
			dict["marketButton"] = marketButton;
			dict["worldMap"] = worldMap;
			dict["City"] = cityImage;
			dict["LeftArrow"] = left_arrow;
			dict["RightArrow"] = right_arrow;
			dict["up_plus_arrow"] = up_plus_arrow;
			
			dict["face"] = face;
			dict["goal"] = goal;
			dict["gold"] = gold;
			
			// Resources
			dict["Food"] = food;
			dict["Copper"] = copper;
			dict["Lumber"] = lumber;
			dict["Iron"] = iron;
			dict["Cotton"] = cotton;
			dict["Oil"] = oil;
			dict["Spices"] = spices;
			dict["Wool"] = wool;
			dict["Salt"] = salt;
			dict["Silk"] = silk;
			dict["Silver"] = silver;
			dict["Coal"] = coal;
			
			// Recipe
			dict["recipe"] = recipe;
			
			// Upgrades
			dict["Sail 1"] = sail_1;
			dict["Anchor"] = anchor;
			dict["Crow's Nest"] = crows_nest_upgrade;
			dict["Rudder"] = rudder_upgrade;
			dict["Motor"] = motor_upgrade;
			dict["Mast"] = plus;
			dict["Crew Quarters"] = plus;
			dict["Expanded Hull"] = plus;
			dict["Compass"] = compass_upgrade;
			dict["Cannon"] = cannon_upgrade;
			dict["Wheel"] = wheel_upgrade;
			dict["Flag 1"] = flag_1_upgrade;
			dict["Flag 2"] = flag_2_upgrade;
			dict["Flag 3"] = flag_3_upgrade;
			dict["Flag 4"] = flag_4_upgrade;
			
			// Change colors so they look different
			dict["Iron Mine"] = mine
			dict["Silver Mine"] = mine;
			dict["Coal Mine"] = mine;
			dict["Copper Mine"] = mine;
			dict["Wool Sweat Shop"] = factory;
			dict["Cotton Sweat Shop"] = factory;
			dict["Silk Sweat Shop"] = factory;
			dict["Oil Field"] = oil_field;
			dict["Spice Stall"] = stall;
			dict["Salt Stall"] = stall;
			dict["Farm"] = farm;
			dict["Timber Mill"] = lumber_yard;
			dict["Warehouse"] = warehouse;
			
			// Actual
			dict["experience_bar"] = experience_bar;
			
			// Paths
			dict["Allegio Routes"] = allegioRoutes;
			dict["Chuan Routes"] = chuanRoutes;
			dict["Chumbucket Routes"] = chumbucketRoutes;
			dict["Dunderfunk Routes"] = dunderfunkRoutes;
			dict["Hai Jing Routes"] = haiJingRoutes;
			dict["Hornswaggle Routes"] = hornswaggleRoutes;
			dict["Marino Routes"] = marinoRoutes;
			dict["Onda Routes"] = ondaRoutes;
			dict["Picaroon Routes"] = picaroonRoutes;
			dict["Shanban Routes"] = shanbanRoutes;
			dict["Tafferel Routes"] = tafferelRoutes;
			dict["Xebek Routes"] = xebekRoutes;
			
		}
		
	}

}